package appapi.service.impl;

import appapi.Global.BusinessException;
import appapi.Request.*;
import appapi.Vo.*;
import appapi.dao.*;
import appapi.dto.AppHomeDto;
import appapi.dto.GetAppRectDto;
import appapi.entity.AppAmg.*;
import appapi.entity.Zhongjiao.*;
import appapi.entity.app.*;
import appapi.entity.basic.SysConfigEntity;
import appapi.entity.record.MonthInspectionEntity;
import appapi.entity.record.MonthdetailEntity;
import appapi.service.IAppApiService;
import appapi.service.SysConfigService;
import appapi.utils.DateUtil;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Component
public class AppApiService implements IAppApiService {
    @Autowired
    private SiteacceptanceMapper siteacceptanceMapper;
    @Autowired
    private EquipmentdismantMapper equipmentdismantMapper;
    @Autowired
    private EquipmentMapper equipmentMapper;
    @Autowired
    private SelfcheckMapper selfcheckMapper;
    @Autowired
    private OnsiteinspectionMapper onsiteinspectionMapper;
    @Autowired
    private MonthinspectionMapper monthinspectionMapper;
    @Autowired
    private RectificationMapper rectificationMapper;
    @Autowired
    private EquipmenttypeMapper equipmenttypeMapper;
    @Autowired
    private StaffMapper staffMapper;
    @Autowired
    private DictionaryMapper dictionaryMapper;
    @Autowired
    private OperatorMapper operatorMapper;
    @Autowired
    private ProjectMapper projectMapper;
    @Autowired
    private EquipmentmaintenanMapper equipmentmaintenanMapper;
    @Autowired
    private OnsitedetailMapper onsitedetailMapper;
    @Autowired
    private AnnexMapper annexMapper;
    @Autowired
    private MonthdetailMapper monthdetailMapper;
    @Autowired
    private SelfcheckdetailMapper selfcheckdetailMapper;
    @Autowired
    private MaintenanitemMapper maintenanitemMapper;
    @Autowired
    private MaintenandetailMapper maintenandetailMapper;
    @Resource
    SysConfigMapper sysConfigMapper;


    //region 前代码
    @Override
    public List<SiteacceptanceDto> GetAccepList(String equipNo) {
        List<SiteacceptanceDto> MyList = siteacceptanceMapper.selectList(equipNo);
        return MyList;
    }

    //设备信息
    @Override
    public List<Map<String, Object>> GetEquip(String equip_no) {
        List<Map<String, Object>> MyList = equipmentMapper.selectList(equip_no);
        return MyList;
    }

    //设备安拆信息
    @Override
    public List<Map<String, Object>> GetDism(long equip_id, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> MyList = equipmentdismantMapper.selectList(equip_id);
        return MyList;
    }

    //设备自检信息
    @Override
    public List<Map<String, Object>> GetSelf(String equip_no, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> MyList = selfcheckMapper.selectList(equip_no);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> GetOnsiteinspection(long equip_id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> MyList = onsiteinspectionMapper.selectList(equip_id);
        return MyList;
    }

    @Override
    public int InsertOnsiteinspection(OnsiteinspectionDto dto) {
        int resulit = onsiteinspectionMapper.insert(dto);
        return resulit;
    }

    @Override
    public List<Map<String, Object>> GetMonthinspection(long equip_id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> MyList = monthinspectionMapper.selectList(equip_id);
        return MyList;
    }

    //分页查询所有设备信息
    @Override
    public List<Map<String, Object>> EquipmentDtoList(EquipmentPageReq equipmentPageReq) {
        PageHelper.startPage(equipmentPageReq.getCurrPage(), equipmentPageReq.getPageSize());
        List<Map<String, Object>> MyList = equipmentMapper.selectPageList(equipmentPageReq);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> GetRectificationList(long equip_id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> MyList = rectificationMapper.selectList(equip_id);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> GetEquipmenttype() {
        List<Map<String, Object>> MyList = equipmenttypeMapper.selectList();
        return MyList;
    }

    @Override
    public List<Map<String, Object>> OnsiteinspectionPageList(OnsiteinspectionPageReq onsiteinspectionPageReq) {
        PageHelper.startPage(onsiteinspectionPageReq.getCurrPage(), onsiteinspectionPageReq.getPageSize());
        List<Map<String, Object>> MyList = onsiteinspectionMapper.selectPageList(onsiteinspectionPageReq);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> MonthinspectionPageList(MonthinspectionPageReq monthinspectionPageReq) {
        PageHelper.startPage(monthinspectionPageReq.getCurrPage(), monthinspectionPageReq.getPageSize());
        List<Map<String, Object>> MyList = monthinspectionMapper.selectPageList(monthinspectionPageReq);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> GetMobile(String staffMobile, String wxid) {
//        List<Map<String, Object>> Mywxid = staffMapper.selectWxid(wxid);//管理人员微信判断
//        if (Mywxid.size() == 0) {
//            Mywxid = operatorMapper.selectAllByWxIdAndOperMobile(wxid, "");//操作人员微信判断
//            if (Mywxid.size() == 0) {
//                Mywxid.get(0).put("admin", false);
//                String jwtToken = JwtUtil.getJwtToken(Mywxid.get(0).get("operMobile").toString(), Mywxid.get(0).get("operName").toString());
//                Mywxid.get(0).put("token", jwtToken);
//                //Mywxid.get(0).put("token",Mywxid.get(0).get("operMobile")+"B"+Mywxid.get(0).get("operName"));
//            }
//        } else {
//            Mywxid.get(0).put("admin", true);
//            //Mywxid.get(0).put("token",Mywxid.get(0).get("staffMobile")+"B"+Mywxid.get(0).get("staffName"));
//            String jwtToken = JwtUtil.getJwtToken(Mywxid.get(0).get("staffMobile").toString(), Mywxid.get(0).get("staffName").toString());
//            Mywxid.get(0).put("token", jwtToken);
//        }

//        if (Mywxid.size()==0){
//            Mywxid=staffMapper.selectMobile(staffMobile);//管理人员手机号判断
//            if (Mywxid.size()==0){
//               Mywxid=operatorMapper.selectAllByWxIdAndOperMobile(wxid,"");//操作人员微信判断
//                Mywxid.get(0).put("admin",false);
//               if (Mywxid.size()==0){
//                   Mywxid=operatorMapper.selectAllByWxIdAndOperMobile("",staffMobile);//操作人员手机号判断
//                   if (Mywxid.size()!=0){//用操作人员手机号登录后将微信保存
//                       Long  operId=(Long)Mywxid.get(0).get("operId");
//                       if(Mywxid.get(0).get("wxId")==null){//当查到手机号是且微信号不为空，新增微信号
//                           operatorMapper.updateByStaffWxid(wxid, operId);//用手机号登录后将微信保存
//                       }
//                   }
//               }
//            }else {
//                Long  staff=(Long)Mywxid.get(0).get("staffId");
//                if(Mywxid.get(0).get("staffWxid")==null){//当查到手机号是且微信号不为空，新增微信号
//                    staffMapper.updateByStaffWxid(wxid, staff);//用手机号登录后将微信保存
//                }
//
//            }
//        }

        return null;
    }

    @Override
    public List<Map<String, Object>> GetDicType(String DicType) {
        List<Map<String, Object>> MyList = dictionaryMapper.selectDicType(DicType);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> Getoperator() {
        List<Map<String, Object>> MyList = operatorMapper.selectOperator();
        return MyList;
    }

    @Override
    public List<Map<String, Object>> GetProject(ProjPageReq projPageReq) {
        List<Map<String, Object>> MyList = projectMapper.selectProject(projPageReq);
        return MyList;
    }

    @Override
    public List<Map<String, Object>> AppSelfcheckPageList(AppSelfcheckPageReq appSelfcheckPageReq) {
        PageHelper.startPage(appSelfcheckPageReq.getCurrPage(), appSelfcheckPageReq.getPageSize());
        List<Map<String, Object>> MyList = selfcheckMapper.selectPageList(appSelfcheckPageReq);
        return MyList;
    }

    @Override
    public int InsertmonthinspectionDto(MonthInspectionEntity entity) {
        int resulit = monthinspectionMapper.insert(entity);
        return resulit;
    }


    @Override
    public int UpdateRectification(RectificationDto rectificationDto) {
        if (rectificationMapper.selectByPrimaryKey(rectificationDto.getRectId()) == null)
            throw new BusinessException(200, "该项目不存在或已被删除!");

        return rectificationMapper.updateByPrimaryKey(rectificationDto);
    }

    @Override
    public List<Map<String, Object>> EquipmentmaintenanPageList(EquipmentmaintenanPageReq equipmentmaintenanPageReq) {
        PageHelper.startPage(equipmentmaintenanPageReq.getCurrPage(), equipmentmaintenanPageReq.getPageSize());
        List<Map<String, Object>> MyList = equipmentmaintenanMapper.selectPageList(equipmentmaintenanPageReq);
        return MyList;
    }

    @Override
    public int UpdateEquipmentmaintenan(EquipmentmaintenanDto equipmentmaintenanDto) {
        if (equipmentmaintenanMapper.selectByPrimaryKey(equipmentmaintenanDto.getMainId()) == null)
            throw new BusinessException(200, "该项目不存在或已被删除!");

        return equipmentmaintenanMapper.updateByPrimaryKey(equipmentmaintenanDto);
    }

    @Override
    public int UpdateMonthinspectionDto(MonthinspectionDto vo) {
        if (monthinspectionMapper.selectByPrimaryKey(vo.getMonthId()) == null)
            throw new BusinessException(200, "该项目不存在或已被删除!");
        //更新月检记录
        MonthInspectionEntity entity = new MonthInspectionEntity();

        return monthinspectionMapper.updateByPrimaryKey(entity);
    }

    @Override
    public JSONObject GetOnsi(JSONObject json) {
        OnsiteinspectionDto onsiteinspectionDto = new OnsiteinspectionDto();

        onsiteinspectionMapper.insertSelective(onsiteinspectionDto);
        System.out.println("username:" + onsiteinspectionDto.getOnsitId());
        System.out.println("username12:" + onsiteinspectionDto.getOnsitId());
        System.out.println("username:" + json);
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public long InsertAddoOnsit(AddOnsiteinspectionVo addOnsiteinspectionVo) {
        //添加巡检记录
        long resulit = onsiteinspectionMapper.insertOnsit(addOnsiteinspectionVo);
        Long onsitId = addOnsiteinspectionVo.getOnsitId();
        //添加明细
        List<OnsitedetailEntity> addList = new ArrayList<>();
        for (AppOnsitedetailImgDto detail : addOnsiteinspectionVo.getOnsitedetail()
        ) {
            OnsitedetailEntity entity = detail.vo2Entity();
            ;
            entity.setImgUrl(detail.getImg().toString());
            entity.setCreateTime(LocalDateTime.now());
            entity.setUpdateTime(LocalDateTime.now());
            entity.setOnsiteId(onsitId);
            addList.add(entity);
        }
        onsitedetailMapper.insertList(addList);
        //将错误的明细新增到整改
        addList.forEach((map) -> {
            if (map.getOnsiteResult() == 1) {
                RectificationDto rec = new RectificationDto();
                rec.setRectSource(map.getOnsiteRecId());
                rec.setRectItem(map.getOnsiteItem());
                rec.setRectNote(map.getAuditNote());
                rec.setEquipId((long) addOnsiteinspectionVo.getEquipId());
                rec.setOperId(addOnsiteinspectionVo.getOnsiteNote().toString());
                rec.setCreateTime(LocalDateTime.now());
                rec.setRectDate(LocalDateTime.now());
                rectificationMapper.insert(rec);
            }
        });

        if (addOnsiteinspectionVo.getAnnexes() != null) {
            //添加巡检信息附件
            List<AnnexEntity> addAnnex = new ArrayList<>();
            for (AnnexDtoImgDto detail : addOnsiteinspectionVo.getAnnexes()) {
                AnnexEntity entity = detail.vo2Entity();
                ;
                entity.setAnnexUrl(detail.getImg().toString());
                entity.setCreateTime(LocalDateTime.now());
                entity.setAnnexType("巡检");
                entity.setRecId(onsitId);
                addAnnex.add(entity);
            }
            annexMapper.insertList(addAnnex);
        }

        return resulit;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public long InsertAddMonth(AddMonthinspectionVo addMonthinspectionVo) {
        //添加月检记录
        long resulit = monthinspectionMapper.insertMonth(addMonthinspectionVo);
        Long onsitId = addMonthinspectionVo.getMonthId();
        //添加明细
        List<MonthdetailEntity> addList = new ArrayList<>();
        for (MonthdetaImgDto detail : addMonthinspectionVo.getMonthdetailDtos()
        ) {
            MonthdetailEntity entity = detail.vo2Entity();
            entity.setImgUrl(detail.getImg().toString());
            entity.setCreateTime(LocalDateTime.now());
            entity.setUpdateTime(LocalDateTime.now());
            entity.setMonthId(onsitId);
            addList.add(entity);
        }
        monthdetailMapper.insertList(addList);
        //将错误的明细新增到整改
        addList.forEach((map) -> {
            if (map.getMonthResult() == 1) {
                RectificationDto rec = new RectificationDto();
                rec.setRectSource(map.getMonthRecId());
                rec.setRectItem(map.getMonthItem());
                rec.setRectNote(map.getAuditNote());
                rec.setEquipId((long) addMonthinspectionVo.getEquipId());
                rec.setOperId(addMonthinspectionVo.getOperator().toString());
                rec.setCreateTime(LocalDateTime.now());
                rec.setRectDate(LocalDateTime.now());
                rectificationMapper.insert(rec);
            }
        });
        if (addMonthinspectionVo.getAnnexes() != null) {
            //添加月检信息附件
            List<AnnexEntity> addAnnex = new ArrayList<>();
            for (AnnexDtoImgDto detail : addMonthinspectionVo.getAnnexes()) {
                AnnexEntity entity = detail.vo2Entity();
                ;
                entity.setAnnexUrl(detail.getImg().toString());
                entity.setCreateTime(LocalDateTime.now());
                entity.setAnnexType("月检");
                entity.setRecId(onsitId);
                addAnnex.add(entity);
            }
            annexMapper.insertList(addAnnex);
        }
        return resulit;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public long InsertAddSelfcheck(AddSelfcheckVo addSelfcheckVo) {
        addSelfcheckVo.setCreateTime(LocalDateTime.now());
        addSelfcheckVo.setCreteTime(LocalDateTime.now());
        //添加自检记录
        long resulit = selfcheckMapper.insertSelfcheck(addSelfcheckVo);
        int onsitId = addSelfcheckVo.getSelfId();
        //添加明细
        List<SelfcheckDetailEntity> addList = new ArrayList<>();
        for (SelfcheckDetailImgDto detail : addSelfcheckVo.getSelfcheckDetailImgDtos()
        ) {
            SelfcheckDetailEntity entity = detail.vo2Entity();
            ;
            entity.setImgurl(detail.getImg().toString());
            entity.setCreateTime(LocalDateTime.now());
            entity.setUpdateTime(LocalDateTime.now());
            entity.setSelfId((long) onsitId);
            addList.add(entity);
        }
        selfcheckdetailMapper.insertList(addList);
        //将错误的明细新增到整改
        addList.forEach((map) -> {
            if (map.getSelfResult() == 1) {
                RectificationDto rec = new RectificationDto();
                rec.setRectSource(map.getSelfRecId());
                rec.setRectItem(map.getSelfItem());
                rec.setRectNote(map.getAuditNote());
                rec.setEquipId(addSelfcheckVo.getEquipId());
                rec.setOperId(addSelfcheckVo.getOperId().toString());
                rec.setCreateTime(LocalDateTime.now());
                rec.setRectDate(LocalDateTime.now());
                rectificationMapper.insert(rec);
            }
        });
        if (addSelfcheckVo.getAnnexes() != null) {
            //添加自检信息附件
            List<AnnexEntity> addAnnex = new ArrayList<>();
            for (AnnexDtoImgDto detail : addSelfcheckVo.getAnnexes()) {
                AnnexEntity entity = detail.vo2Entity();
                ;
                entity.setAnnexUrl(detail.getImg().toString());
                entity.setCreateTime(LocalDateTime.now());
                entity.setAnnexType("自检");
                entity.setRecId((long) onsitId);
                addAnnex.add(entity);
            }
            annexMapper.insertList(addAnnex);
        }
        return resulit;
    }

    @Override
    public void InsertEquipmentmaintenan(EquipmentmaintenanDto equipmentmaintenanDto) {

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateRectificationList(updateRectificationListVo up) {
        List<RectificationEntity> addList = new ArrayList<>();
        for (RectificationImgDto detail : up.getRectificationImgDtos()
        ) {
            RectificationEntity entity = detail.vo2Entity();
            entity.setRectImgs(JSON.toJSONString(detail.getImg()));
            addList.add(entity);
        }
        addList.forEach((map) -> {
            rectificationMapper.updateByPrimaryKeyList(map);
        });
        return addList.size();
    }

    @Override
    public List<Map<String, Object>> GetMaintenanitem(long equipTypeId) {
        List<Map<String, Object>> MyList = maintenanitemMapper.selectEquipTypeId(equipTypeId);
        return MyList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int AddMaintenandetailList(AddMaintenandetailListVo add) {
        List<MaintenandetailEntity> addList = new ArrayList<>();
        for (MaintenandetailImgDto detail : add.getMaintenandetailImgDtos()
        ) {
            MaintenandetailEntity entity = detail.vo2Entity();
            ;
            entity.setMaintenanImgs(JSON.toJSONString(detail.getImg()));
            addList.add(entity);
        }
        maintenandetailMapper.addInsert(addList);
        return addList.size();
    }

    @Override
    public List<Map<String, Object>> GetOnsitedetailList(long onsiteId) {
        List<Map<String, Object>> MyList = onsitedetailMapper.selectAllByOnsiteId(onsiteId);
        MyList.forEach(map -> {
            List<Map<String, Object>> annex = annexMapper.selectAnnexsrecId(map.get("onsiteRecId").toString());
            map.put("annexList", annex);
        });
        return MyList;
    }

    @Override
    public List<Map<String, Object>> GetMonthdetailList(long monthId) {
        List<Map<String, Object>> MyList = monthdetailMapper.selectAllByMonthId(monthId);
        MyList.forEach(map -> {
            List<Map<String, Object>> annex = annexMapper.selectAnnexsrecId(map.get("monthRecId").toString());
            map.put("annexList", annex);
        });
        return MyList;
    }

    @Override
    public List<Map<String, Object>> Getmaintenandetail(long mainId) {
        List<Map<String, Object>> MyList = maintenandetailMapper.selectAllByMainIdList(mainId);
        return MyList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<WxHomePageVo> GetWxHomePage(AppHomeDto dto) {
        //模拟token解析
//        String[] token = JwtUtil.getUserInfoByJwtToken(request);
        //String[] token = JwtUtil.getUserInfoByJwtToken(request);

        List<WxHomePageVo> list = new ArrayList<>();
        GetAppRectDto getAppRectDto = new GetAppRectDto();
        //判断是否是操作人员,如果是操作人员,则多看一条设备整改
        //OperatorDto operatorDto = operatorMapper.selectAllByOperMobileAndOperName(token[1], token[0]);

        getAppRectDto.setProjId(dto.getProjId());
        //管理人员看的是 该项目待审核状态的整改数据,整改已完成,数据被回退
        if (dto.getType() == 0) {
            getAppRectDto.setType(0);
        }
        //操作人员(整改人员) 发起人只能看自己的,并且流程未走完的
        else if (dto.getType() == 1) {
            getAppRectDto.setUserId(dto.getUserId());
            getAppRectDto.setType(1);
        }
        //维修人员 只能看这个项目下审核通过的待整改
        else {
            getAppRectDto.setAuditState(1);
            getAppRectDto.setRectState(0);
        }

        //根据条件查到的数据
        List<RectificationDto> rectificationList = rectificationMapper.selectAllByOperIdAndRectState(getAppRectDto);
        List<WxHomePageVo> collect = rectificationList.stream().map((data) -> {
            WxHomePageVo vo = new WxHomePageVo();
            vo.setTitle("设备整改");
            vo.setRecordId(data.getRectId());
            vo.setContent(data.getRectRequire());
            vo.setEquipNo(data.getEquipNo());
            ZoneId zoneId = ZoneId.systemDefault();
            ZonedDateTime zdt = data.getCreateTime().atZone(zoneId);
            vo.setDataTime(Date.from(zdt.toInstant()));
            vo.setAuditState(data.getAuditState());
            vo.setRectState(data.getRectState());
            vo.setEquipId(data.getEquipId());
            return vo;
        }).collect(Collectors.toList());

        list.addAll(collect);

        //查到预警天数(指离上次多久预警)
        //Map<String, Object> monthWarnDay = dictionaryMapper.selectDicType("月检预警").get(0);
        //Integer warnDay =Integer.parseInt( monthWarnDay.get("dictValue").toString())
        SysConfigEntity sysConfigEntity = sysConfigMapper.selectByPrimaryKey(1);
        Integer warnDay = sysConfigEntity.getConfAlarmdate();

        //判断是否是管理人员,如果是管理人员,则只看两条月检相关信息
//        StaffDto staffDto = staffMapper.selectAllByStaffMobileAndStaffName(split[0], split[1]);

        //查到每台设备上次月检时间
        List<Map<String, Object>> equips = monthinspectionMapper.selectMonthWarn(dto.getProjId());

        //筛出预警数据
        List<WxHomePageVo> collect2 = equips.stream()
                .filter((time -> time.get("monthDate") != null))
                .filter((warn) -> {
                    //将上月时间转换为Date
                    Date stratDate = DateUtil.getString2Date(warn.get("monthDate").toString());
                    //比较当天时间与上次月检时间,判断是否大于设置时间,如果大于则预警
                    return DateUtil.getDiffDays(stratDate, DateUtil.getCurrentDate()) > warnDay;
                })
                .map((equip) -> {
                    WxHomePageVo vo = new WxHomePageVo();
                    //如果为空则为新增的设备,并且没有进行过月检,添加预警数据
//                    if (equip.get("monthDate") == null) {
//                        vo.setTitle("月检预警");
//                        vo.setContent("月检即将超时");
//                        vo.setEquipNo(equip.get("equipNo").toString());
//                        vo.setEquipId(equip.get("equipId").toString());
//                    } else
//                    {
                    //比较当天时间与上次月检时间,判断是否大于设置时间,如果大于则预警
                    // if () {
                    vo.setTitle("月检预警");
                    vo.setRecordId((Long) equip.get("monthId"));
                    vo.setContent("月检即将超时");
                    vo.setEquipNo(equip.get("equipNo").toString());
                    vo.setEquipId((Long) equip.get("equipId"));
                    vo.setDataTime(DateUtil.getString2Date(equip.get("monthDate").toString()));
                    //}
//                    }
                    return vo;
                })
                .collect(Collectors.toList());
        list.addAll(collect2);

        //Date d1 = new Date();
        //boolean before = d1.before(DateUtil.getString2Date("2022-01-01 00:00:00"));     //false

        //now.before(date)  指  "date"  这个时间是否在    "now"   之前
        //筛出超时告警数据
        collect2.stream()
                .filter((warn) -> {
                    Map<String, Object> equip = equipmentMapper.selectEquiDetail(warn.getEquipId());
                    Date certificateReexamine = DateUtil.getString2Date(equip.get("certificateReexamine").toString());
                    return new Date().after(certificateReexamine);
                })
                .map(map -> {
                    map.setTitle("月检报警");
                    map.setContent("超时未月检");
                    return map;
                })
                .collect(Collectors.toList());
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public long AddRectificationAll(AddRectificationVo addRectification) {
        List<RectificationEntity> addList = new ArrayList<>();
        for (AddRectificationImgDto detail : addRectification.getAddRectificationImgDtos()
        ) {
            RectificationEntity entity = detail.vo2Entity();
            ;
            entity.setRectImgs(JSON.toJSONString(detail.getImg()));
            entity.setCreateTime(LocalDateTime.now());
            entity.setUpdateTime(LocalDateTime.now());
            //addList.add(entity);
            ;
            rectificationMapper.insertRectificationAll2(entity);
            long onsitId = entity.getRectId();
            if (detail.getAnnexes() != null) {
                //添加自检信息附件
                List<AnnexEntity> addAnnex = new ArrayList<>();
                for (AnnexDtoImgDto detail2 : detail.getAnnexes()) {
                    AnnexEntity entity2 = detail2.vo2Entity();
                    ;
                    entity2.setAnnexUrl(detail2.getImg().toString());
                    entity2.setCreateTime(LocalDateTime.now());
                    entity2.setAnnexType("整改自增");
                    entity2.setRecId(onsitId);
                    addAnnex.add(entity2);
                }
                annexMapper.insertList(addAnnex);
            }
        }

        //rectificationMapper.insertRectificationAll(addList);
        //int onsitId=addSelfcheckVo.getSelfId();

        return addList.size();

    }
//endregion


}
